package com.crm.task;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import org.apache.log4j.Logger;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

import com.crm.common.CrmInit;
import com.crm.task.executer.DBBackupExecuter;

public class CrmTask {
	private static Logger logger = Logger.getLogger(CrmTask.class);

	private static String express = CrmInit.DB_BACKUP_EXP;

	// 初始化创建搜索索引
	public static void readyTask() {
		try {
			SchedulerFactory schedulerFactory = new StdSchedulerFactory();
			Scheduler scheduler = schedulerFactory.getScheduler();
			JobDetail jobDetail = newJob(DBBackupExecuter.class).withIdentity("backupJob", "backupGroup").build();
			CronTrigger trigger = newTrigger().withIdentity("backupTrigger", "backupGroup")
					.withSchedule(cronSchedule(express)).build();
			scheduler.scheduleJob(jobDetail, trigger);
			scheduler.start();
			logger.info("CrmTask.readyTask was ok, the backup db as express [ " + express + "].");
		} catch (Exception e) {
			logger.error("CrmTask.readyTask has error:", e);
		}
	}

}
